package com.wanmait.recycle.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wanmait.recycle.pojo.Rubbish;
import com.wanmait.recycle.pojo.Unit;
import com.wanmait.recycle.service.RubbishService;
import com.wanmait.recycle.service.RubbishUnitService;
import com.wanmait.recycle.service.UnitService;

@Controller
@RequestMapping("/manager/unit")
public class UnitController {

	@Resource
	private UnitService unitService;
	@Resource
	private RubbishService rubbishService;
	@Resource
	private RubbishUnitService rubbishUnitService;
	
	
	@RequestMapping("unitList")
	@ModelAttribute("unites")
	public List<Unit> unitList(){
		
		return unitService.findAllUnit();
		
	}
	
	@RequestMapping("R_unitList")
	@ModelAttribute("R_units")
	public List<Rubbish> R_unitList(){
		
		return rubbishService.findAll();
		
	}
	
	@RequestMapping("deleteOne")
	@ResponseBody
	public void deleteOne(Integer id) {
		
		unitService.deleteOne(id);
	}
	
	@RequestMapping("recallOne")
	@ResponseBody
	public void recallOne(Integer id) {
		
		unitService.recallOne(id);
		
	}
	
	@RequestMapping("delete")
	@ResponseBody
	public void delete(String ids) {
		
		unitService.delete(ids);
	}
	
	@RequestMapping("unitAdd")
	public void unitAdd() {
		
	
		
	}
	@RequestMapping("R_unitAdd")
	@ModelAttribute("units")
	public List<Unit> R_unitAdd() {
	 	return unitService.findAll();
	
		
	}
	
	@RequestMapping("unitChange")
	@ResponseBody
	public void unitChange(String name) {
		
		unitService.addUnit(name);
		
		
	}
	
	@RequestMapping("unitChange1")
	@ResponseBody
	public void unitChange1(Unit unit) {
		
		unitService.updateUnit(unit);
		
	}
	
	@RequestMapping("deleteOneUnit")
	@ResponseBody
	public void deleteOneUnit(Integer rubbishId,Integer unitId) {
		
		rubbishUnitService.deleteOneUnit(rubbishId,unitId);
	}
	
	
	@RequestMapping("R_unitChange")
	@ResponseBody
	public void R_unitChange(Integer rubbishId,Integer unitId) {
		
		rubbishUnitService.insertOneUnit(rubbishId,unitId);
		
	}
	
	@RequestMapping("changeSortCount")
	@ResponseBody
	public void changeSortCount(Integer Tid,Integer Tcount,Integer id, Integer count) {
		
		
		unitService.changeSortCount(Tid,count);
		unitService.changeSortCount(id,Tcount);
		
	}
	
}









